package com.zlh.mq;

import com.alibaba.fastjson.JSONObject;
import com.zlh.config.RocketMQPullConsumer;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageExtBatch;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zlhuang9
 * @Description
 * @Date 2024-06-18
 */
@Component
//@RocketMQMessageListener(topic = "batch-Topic", consumerGroup = "batch-Group",
//        messageModel = MessageModel.CLUSTERING, nameServer = "localhost:9876")
@RocketMQPullConsumer(topic = "batch-Topic", consumerGroup = "batch-Group")
public class BatchConsumer implements RocketMQListener<List<MessageExt>> {
    @Override
    public void onMessage(List<MessageExt> message) {
        System.out.println("list size: " + message.size());
        try {
            // 模拟处理时长
            Thread.sleep(15000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
//        for (MessageExt ext : message) {
//            System.err.println(new String(ext.getBody()));
//        }
//        System.out.println(JSONObject.toJSONString(message) + ", list size: " + message.size());
    }
}
